package com.k.kpp;

import com.k.kc.util.base64.base64url.Base64UrlUtility;
import org.apache.commons.lang.StringUtils;

import java.io.File;

/**
 * Created by 170623910 on 2021/9/23.
 */
public class Test {
    public static void main(String[] args) {

//            testBase64();
//            for(int i=0;i<10;i++){
//                // 判断奇偶数
//                boolean isOdd = (i&1)==0?true:false;
//                System.out.println(i +":"+(i&1));
//
//                // 取反
//                // System.out.println(i + ":"+ (~i+1));
//            }

        System.out.println(StringUtils.isEmpty("   "));
    }
    public static void testFile(){
        try {
            File file = new File("h:/");
            if(file.isDirectory()){
                File[] files = file.listFiles();
                for(File file1:files){
                    String name = file1.getName();
                    String absPath = file1.getAbsolutePath();
                    // use this normal
                    String canPath = file1.getCanonicalPath();
                    boolean isDir = file1.isDirectory();
                    System.out.println(name +"-"+"isDir:"+isDir+" - "+"absPath:"+absPath+" - "+"canPath:"+canPath);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void testBase64() throws Exception {
        String header = "{\"alg\":\"HS256\"}";
        String claims="{\"sub\":\"Joe\"}";
        header="{\"alg\":\"HS256\",\"typ\":\"JWT\"}";
        claims="{\"sub\":\"1234接口和健康和健康567890调的度的\",\"name\":\"John Doe aaaabbasdfha哈哈bd气味哦咯哈儿44童d\"}";
        byte[] headerByte = header.getBytes("UTF-8");
        byte[] bodyByte = claims.getBytes("UTF-8");

        // jdk
        System.out.println("base64 header0:"+ java.util.Base64.getEncoder().encodeToString(headerByte));
        // commons-net-3.6
        System.out.println("base64 header1:"+org.apache.commons.net.util.Base64.encodeBase64String(headerByte));
        System.out.println("base64 header2:"+org.apache.commons.net.util.Base64.encodeBase64URLSafeString(headerByte));
        System.out.println("base64 header3:"+ Base64UrlUtility.encode(headerByte));
        System.out.println("=======================");
        System.out.println("base64 body0:"+java.util.Base64.getEncoder().encodeToString(bodyByte));
        System.out.println("base64 body1:"+org.apache.commons.net.util.Base64.encodeBase64String(bodyByte));
        System.out.println("base64 body2:"+org.apache.commons.net.util.Base64.encodeBase64URLSafeString(bodyByte));
        System.out.println("base64 body3:"+ Base64UrlUtility.encode(bodyByte));
        byte a = (byte) 254;
        int ab =a & 0xff;
        System.out.println(ab);
    }
}
